package itsm.isperp.framework.web.response;

import java.util.List;

import org.springframework.data.domain.Page;

/**
 * 服务器应该返回DataTables的 JSON 格式数据
 * 
 * @author lizx
 * @date 2013-1-16
 * @version V1.0
 */
public class DataTablesResponse<T> {

	/**
	 * 实际的行数
	 */
	public int iTotalRecords;

	/**
	 * 过滤之后，实际的行数
	 */
	public int iTotalDisplayRecords;

	/**
	 * 来自客户端 sEcho 的没有变化的复制品
	 */
	public String sEcho;

	/**
	 * 可选，以逗号分隔的列名
	 */
	public String sColumns;

	/**
	 * 数组的数组，表格中的实际数据
	 */
	public List<T> aaData;

	public DataTablesResponse() {
	}

	public DataTablesResponse(Page<T> page) {
		this.iTotalRecords = (int) page.getTotalElements();
		this.iTotalDisplayRecords = 10;
		this.aaData = page.getContent();

	}

	public DataTablesResponse(String sEcho, Integer iTotalRecords,
			Integer iTotalDisplayRecords, List<T> aaData) {
		super();
		this.sEcho = sEcho;
		this.iTotalRecords = iTotalRecords;
		this.iTotalDisplayRecords = iTotalDisplayRecords;
		this.aaData = aaData;
	}

	@Override
	public String toString() {
		return "DataTablesResponse [iTotalDisplayRecords="
				+ iTotalDisplayRecords + ", iTotalRecords=" + iTotalRecords
				+ ", aaData=" + aaData + "]";
	}
}
